package com.mcp_life.module.userbasemodules.service.impl;

import com.mcp_life.common.context.UserContextHolder;
import com.mcp_life.entity.dto.UserAddressDTO;
import com.mcp_life.entity.pojo.UserAddress;
import com.mcp_life.module.userbasemodules.mapper.AddressMapper;
import com.mcp_life.module.userbasemodules.service.AddressService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

public class AddressServiceImpl implements AddressService {
    @Autowired
    private AddressMapper addressMapper;
    @Override
    public void Insert(UserAddressDTO addressDTO) {
        UserAddress userAddress = new UserAddress();
        BeanUtils.copyProperties(addressDTO, userAddress);
        userAddress.setUserId(UserContextHolder.getUserId());
        userAddress.setStatus(1);
        userAddress.setCreateTime(new java.util.Date());
        userAddress.setUpdateTime(new java.util.Date());
        userAddress.setIsDefault(0);
        if (userAddress.getType()==null){
            userAddress.setType(0);
        }
        addressMapper.insert(userAddress);
    }

    @Override
    public void update(UserAddressDTO addressDTO) {
            addressMapper.update(addressDTO);
    }
}
